import { _decorator, Component, Node, PhysicsSystem2D, Collider2D, Contact2DType, IPhysics2DContact, RigidBody, director, RigidBody2D, v2, PHYSICS_2D_PTM_RATIO, geometry, ERaycast2DType, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('wulipengzhuang')
export class wulipengzhuang extends Component {
	start() {
		PhysicsSystem2D.instance.enable = true
		
		
		let rbody = this.getComponent(RigidBody2D)
		// 牛 力是会累加的
		// rbody.applyForce(v2(100,0),v2(0,0),true)
		// rbody.applyForceToCenter(v2(100,0),true)
		// 线速度  像素/s   速度不变的
		rbody.linearVelocity=v2(1,0)
		let collider = this.getComponent(Collider2D);
		if (collider) {
			collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
		}
	}
	onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D,contcat) {
		// 获得碰撞点
		console.debug(contcat.getWorldManifold())
	}
	
	update(deltaTime: number) {
		let phy = PhysicsSystem2D.instance
		//转换为世界坐标系
		let newp = this.node.getParent().getComponent(UITransform).convertToWorldSpaceAR(this.node.getPosition())
		//然后就能检测到了
		let res = phy.raycast(newp, v2(newp.x, newp.y - 200))
		console.debug(res)
	}
}

